<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" clearable v-model="ordersInfo.query" @clear="getOrdersList">
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="ordersList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="订单编号" prop="order_number" min-width="120px"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="warning" size="mini" v-if="scope.row.pay_status === '0'">未付款</el-tag>
            <el-tag type="success" size="mini" v-else-if="scope.row.pay_status === '1'">付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="create_time"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="editDialogVisible = true"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="getLogInfo(scope.row.user_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="ordersInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="ordersInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 编辑 -->
    <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="50%">
      <el-form>
        <el-form-item label="省市区/县">
          <el-cascader :options="areaData" expand-trigger="hover"></el-cascader>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看物流 -->
    <el-dialog title="查看物流进度" :visible.sync="seenDialogVisible" width="50%">
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(item, index) in logInfo"
          :key="index"
          :icon="index===0?'el-icon-location':''"
          :color="index===0?'#f00':''"
          :timestamp="item.time"
        >{{item.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import * as orders from '../../api/orders'
import chinaDate from '../../util/china'
export default {
  data () {
    return {
      ordersInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      ordersList: [],
      total: 0,
      editDialogVisible: false,
      areaData: chinaDate,
      seenDialogVisible: false,
      logInfo: []
    }
  },
  created () {
    this.getOrdersList()
  },
  methods: {
    async getOrdersList () {
      const { data: res } = await orders.getOrdersList(this.ordersInfo)
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      console.log(res)
      this.ordersList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (newSize) {
      this.ordersInfo.pagesize = newSize
      this.getOrdersList()
    },
    handleCurrentChange (newNum) {
      this.ordersInfo.pagenum = newNum
      this.getOrdersList()
    },
    async getLogInfo (id) {
      const { data: res } = await orders.getLogInfo(1106975712662)
      console.log(res)
      if (res.meta.status !== 200) return this.$message.error(res.meta.message)
      this.logInfo = res.data
      this.seenDialogVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
